#pragma once
#include "map.h"
#include <Windows.h>
#include <conio.h>
#include <deque>
#define TOTAL_BILLS 40
#define TIMES_TO_SHUFFLE 1000
#define DRAWING_ANCHOR_POINTX  1
#define DRAWING_ANCHOR_POINTY  2
#define BILL_HEIGHT 5
#define BILL_WIDTH 20
#define BILLSPERCOLLUMN 4
#define PURPLE 5
#define YELLOW 14
struct Bill
{
	int value;
	Map icon;
};

class Pot
{
private:

public:
	//Public variables
	int potSize;
	deque<Bill*> cash;	//All the money in the game
	deque<Bill*> currentPot;	//The current Money up for grabs.
	bool potLoaded;
	//Public functions
	Pot(): potSize(5), potLoaded (false)
	{
		
		for (int i = 0; i < TOTAL_BILLS; i++)
		{
			Bill * temp = new Bill;
			if (i < 10)
			{
				temp->value = 20000;
				temp->icon.loadFile("20kbill.txt");
			}
			else if (i >= 10 && i < 25)
			{
				temp->value = 10000;
				temp->icon.loadFile("10kbill.txt");
			}
			else if (i >= 25 && i < TOTAL_BILLS)
			{
				temp->value = 5000;
				temp->icon.loadFile("5kbill.txt");
			}
			cash.push_front(temp);
		}
	}

	void shuffle()
	{
		int a, b;
		Bill * temp;
		for (int i = 0; i < TIMES_TO_SHUFFLE; ++i)
		{
			a = rand() % TOTAL_BILLS;
			b = rand() % TOTAL_BILLS;
			if (a != b)
			{
				temp = cash[a];
				cash[a] = cash[b];
				cash[b] = temp;
			}
		}
	}
	void update()
	{
		if (potLoaded == false)
		{
			for (int i = currentPot.size(); i < potSize; i++)
			{
				if (cash.size() > 0)
				{
					currentPot.push_front(cash.front());
					cash.pop_front();
				}
			}
		}
		potLoaded = true;
	}
	int getpotSize() {return potSize;}
	Bill* getCash(int a_index) {return cash[a_index];}
	Bill* getPot(int a_index) {return currentPot[a_index];}
	//Game Loop functions
	void draw()
	{
		if (currentPot.size() > 0)
		{
			int collumn = 0, row = 0;
			for (int i = 0; i < potSize; i++)
			{
				if (currentPot[i]->value == 5000)
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				if (currentPot[i]->value == 10000)
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | YELLOW);
				if (currentPot[i]->value == 20000)
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | PURPLE);
				currentPot[i]->icon.draw(DRAWING_ANCHOR_POINTX + (BILL_WIDTH*collumn), DRAWING_ANCHOR_POINTY + (BILL_HEIGHT*row));
				row++;
				if (row >= BILLSPERCOLLUMN)
				{
					row = 0;
					collumn++;
				}
			}
		}
	}
};